<?php

namespace Partner\Controller;

use Think\Controller;

class IndexController extends ComController {

    public $layout = 'admin';

    public function init() {
        
    }

    public function index() {
        $where = array(
            'seller_id' => $this->Seller['seller_id'],
            'is_del' => '0'
        );
        $good_num = M('goods')->where($where)->count();
        $codeObj = M('code as c');
        $join = array('left join sm_goods as go on c.good_id = go.id');
        $where1 = array(
            'go.seller_id' => $this->Seller['seller_id'],
            'c.status' => 1
        );
        $where2 = array(
            'go.seller_id' => $this->Seller['seller_id'],
            'c.status' => 2
        );
        $code1_num = $codeObj->where($where1)->join($join)->count('status');
        $code2_num = $codeObj->where($where2)->join($join)->count('status');
        //dump(M('code')->getLastSql());
        //dump($code2_num);die;

        $this->assign('code1_num', $code1_num);
        $this->assign('code2_num', $code2_num);
        $this->assign('good_num', $good_num);
        $this->display();
    }
    
    /**
 * 获取用户真实 IP
 */
function getIP()
{
    static $realip;
    if (isset($_SERVER)){
        if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
            $realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
        } else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
            $realip = $_SERVER["HTTP_CLIENT_IP"];
        } else {
            $realip = $_SERVER["REMOTE_ADDR"];
        }
    } else {
        if (getenv("HTTP_X_FORWARDED_FOR")){
            $realip = getenv("HTTP_X_FORWARDED_FOR");
        } else if (getenv("HTTP_CLIENT_IP")) {
            $realip = getenv("HTTP_CLIENT_IP");
        } else {
            $realip = getenv("REMOTE_ADDR");
        }
    }
 
 
    return $realip;
}
 
 
/**
 * 获取 IP  地理位置
 * 淘宝IP接口
 * @Return: array
 */
function getCity($ip)
{
$url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;
$ip=json_decode(file_get_contents($url)); 
if((string)$ip->code=='1'){
  return false;
  }
  $data = (array)$ip->data;
return $data; 
}

}